/**********Reg Event***************/
/*
	var element is element id name
	var e is reg to element event
	var fn is reg to element event function
*/
function addListener(element,e,act){
	if(element.addEventListener){
          element.addEventListener(e,call_action,false);
     } else {
          element.attachEvent("on" + e,call_action);
     }
}
window.onload = function(){
	/*
	<?for($i=0;$i<count($headermenu);$i++){?>
	var <?=$headermenu[$i]?> =  document.getElementById("<?=$headermenu[$i]?>");
	addListener(<?=$headermenu[$i]?>,"click",call_<?=$headermenu[$i]?>);
	<?}?>
	*/
	var menuList = new Array("system_setting","system_setting","user_manage","products_manage","contents_review","system_tool","ad_manage","recommended_control");
	for(var n=0;n<menuList.length;n++)
	{
		var idName = menuList[n];
		var idName = document.getElementById(idName);
		addListener(idName,"click",idName);
	}
}
/************end*******************/

function call_action()
{
	//var act  = event.srcElement.id ;
	if(document.all)
      act = event.srcElement.id;
     else
      act = arguments[0].target.id;
	window.location.href="index.php?action="+act;
}

/*
<?for($i=0;$i<count($headermenu);$i++){?>
function call_<?=$headermenu[$i]?>()
{
 	callServer('GET','/?<?=$headermenu[$i]?>',false);
 	return;
}
<?}?>
*/
/**************Ajax**************/
function Ajax()
{
	var request = false;
			if(window.XMLHttpRequest) {
				request = new XMLHttpRequest();
				if(request.overrideMimeType) {
					request.overrideMimeType('text/xml');
				}
			} else if(window.ActiveXObject) {
				var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
				for(var i=0; i<versions.length; i++) {
					try {
						request = new ActiveXObject(versions[i]);
						if(request) {
							return request;
						}
					} catch(e) {}
				}
			}
	return request;
}
function callServer(method,url,wait) {
  var xmlHttp = Ajax();
  if(!xmlHttp)
  {
	  alert('You Browser cannot run ajax');
	  return;
  }
  // Open a connection to the server
  xmlHttp.open(method, url, wait);
  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = writeMainRight();
  // Send the request
  xmlHttp.send(null);
}
function writeMainRight()
{
	if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById("right").text = response;
  }
}


